Skip to content

关闭控制台高级 - CloseConsoleEx

函数简介

关闭由 打开控制台高级 - OpenConsoleEx 打开的控制台。type 需与打开时一致;type=1 时通过 hwnd 定位目标进程。

接口名称

CloseConsoleEx

DLL调用

c
int32_t CloseConsoleEx(int64_t instance, int64_t hwnd, int32_t type);

参数说明

参数名类型说明
instance长整数型OLAPlug 对象的指针,由 CreateCOLAPlugInterFace 接口生成。
hwnd长整数型目标窗口句柄;type!=0 时用于定位目标进程。
type整数型关闭类型,见下表。

type 取值

说明
0软件本身(插件进程)控制台
1目标窗口进程控制台

示例

OpenConsoleEx 使用相同的 hwnd/type 配对关闭。

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

int64_t hwnd = 0;
ola.OpenConsoleEx(hwnd, 0);
ola.LogSetTarget(0, 2);
ola.LogInfo("before close ex");
int ret = ola.CloseConsoleEx(hwnd, 0);
if (ret != 1) {
    return;
}
csharp
using System;
using OLAPlug;

var ola = new OLAPlugServer();

long hwnd = 0;
ola.OpenConsoleEx(hwnd, 0);
ola.LogSetTarget(0, 2);
ola.LogInfo("before close ex");
int ret = ola.CloseConsoleEx(hwnd, 0);
if (ret != 1) return;
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()

hwnd = 0
ola.OpenConsoleEx(hwnd, 0)
ola.LogSetTarget(0, 2)
ola.LogInfo("before close ex")
ret = ola.CloseConsoleEx(hwnd, 0)
if ret != 1:
    raise RuntimeError("CloseConsoleEx failed")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();

long hwnd = 0;
ola.OpenConsoleEx(hwnd, 0);
ola.LogSetTarget(0, 2);
ola.LogInfo("before close ex");
int ret = ola.CloseConsoleEx(hwnd, 0);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()

hwnd := int64(0)
ola.OpenConsoleEx(hwnd, 0)
ola.LogSetTarget(0, 2)
ola.LogInfo("before close ex")
ret := ola.CloseConsoleEx(hwnd, 0)
if ret != 1 {
    return
}
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();

let hwnd = 0i64;
ola.open_console_ex(hwnd, 0);
ola.log_set_target(0, 2);
ola.log_info("before close ex");
let ret = ola.close_console_ex(hwnd, 0);
if ret != 1 {
    return;
}
cpp
var ola = com("OlaPlug.OlaSoft")

var hwnd = 0
ola.OpenConsoleEx(hwnd, 0)
ola.LogSetTarget(0, 2)
ola.LogInfo("before close ex")
var ret = ola.CloseConsoleEx(hwnd, 0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")

hwnd = 0
ola.OpenConsoleEx hwnd, 0
ola.LogSetTarget 0, 2
ola.LogInfo "before close ex"
ret = ola.CloseConsoleEx(hwnd, 0)
text
.局部变量 ola, OLAPlug
.局部变量 ret, 整数型

ola.Create ()

.局部变量 hwnd, 长整数型
hwnd = 0
ola.OpenConsoleEx (hwnd, 0)
ola.LogSetTarget (0, 2)
ola.LogInfo (“before close ex”)
ret = ola.CloseConsoleEx (hwnd, 0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();

var hwnd = 0;
ola.OpenConsoleEx(hwnd, 0);
ola.LogSetTarget(0, 2);
ola.LogInfo("before close ex");
var ret = ola.CloseConsoleEx(hwnd, 0);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer

长整数 hwnd = 0
ola.OpenConsoleEx(hwnd, 0)
ola.LogSetTarget(0, 2)
ola.LogInfo("before close ex")
整数 ret = ola.CloseConsoleEx(hwnd, 0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

int64_t hwnd = 0;
ola.OpenConsoleEx(hwnd, 0);
ola.LogSetTarget(0, 2);
ola.LogInfo("before close ex");
int32_t ret = ola.CloseConsoleEx(hwnd, 0);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long logger = 0;

int64_t hwnd = 0;
OpenConsoleEx(instance, hwnd, 0);
LogSetTarget(instance, 0, 2);
LogInfo(instance, "before close ex");
int ret = CloseConsoleEx(instance, hwnd, 0);
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int OpenConsoleEx(long ola, long hwnd, int type);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int CloseConsoleEx(long ola, long hwnd, int type);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogSetTarget(long ola, long loggerHandle, int targetFlags);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogInfo(long ola, string message);

long instance = CreateCOLAPlugInterFace();
long logger = 0;

long hwnd = 0;
OpenConsoleEx(instance, hwnd, 0);
LogSetTarget(instance, 0, 2);
LogInfo(instance, "before close ex");
int ret = CloseConsoleEx(instance, hwnd, 0);
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
logger = 0

hwnd = 0
ola.OpenConsoleEx(instance, hwnd, 0)
ola.LogSetTarget(instance, 0, 2)
ola.LogInfo(instance, b"before close ex")
ret = ola.CloseConsoleEx(instance, hwnd, 0)

返回值

返回值说明
1成功。
0失败。

注意事项

项目说明
type 一致应与 OpenConsoleEx 打开时使用的 type 一致。